/*
 * BaseFragment.java
 * classes : com.ruint.core.app.BaseFragment
 * @author ruint
 * V 1.0.0
 * Create at 2014-12-11 上午10:55:45
 */
package com.ruint.core.app;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruint.core.interfaces.ViewFinder;
import com.ruint.core.utils.preferences.CorePreferences;

/**
 * com.ruint.core.app.BaseFragment
 * 
 * @author ruint <br/>
 *         create at 2014-12-11 上午10:55:45
 */
public abstract class BaseFragment extends Fragment implements ViewFinder {
  protected View rootView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CorePreferences.DEBUG("fragment onCreate:" + getClassName());
  }

  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    if (rootView == null) {
      rootView = inflater.inflate(getLayoutResID(), container, false);
    }
    findViews(rootView);
    onLoadingData();
    return rootView;
  }

  @SuppressWarnings("unchecked")
  @Override
  public <T extends View> T findView(T t, int id) {
    return (T) rootView.findViewById(id);
  }

  @Override
  public void onDestroy() {
    super.onDestroy();
    CorePreferences.DEBUG("fragment onDestroy:" + getClassName());
  }

  @Override
  public void onDetach() {
    super.onDetach();
    CorePreferences.DEBUG("fragment onDetach:" + getClassName());
  }

  @Override
  public void onPause() {
    super.onPause();
    CorePreferences.DEBUG("fragment onPause:" + getClassName());
  }

  @Override
  public void onResume() {
    super.onResume();
    CorePreferences.DEBUG("fragment onResume:" + getClassName());
  }

  protected String getClassName() {
    return this.getClass().getName();
  }

  protected abstract int getLayoutResID();

  protected abstract void findViews(View rootView);

  protected abstract void onLoadingData();
}
